package com.zzw.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.zzw.entity.OauthAccessToken;
import com.zzw.entity.OauthApprovals;
import com.zzw.entity.SysUser;
import com.zzw.service.OauthAccessTokenService;
import com.zzw.service.OauthApprovalsService;
import com.zzw.service.SysUserService;
import com.zzw.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private OauthAccessTokenService oauthAccessTokenService;
    @Autowired
    private OauthApprovalsService oauthApprovalsService;
    @Autowired
    private SysUserService sysUserService;

    @RequestMapping("/hello")
    public JsonResult hello() {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData("hello");
        return jsonResult;
    }

    @RequestMapping("/add")
    /**
     * @Athor:xiezhongjiang
     * @Description:测试插入
     * @Date:2017/10/30 17:21
     * @Param:[]
     * @return com.zzw.web.JsonResult
     */
    public JsonResult add() {
        JsonResult jsonResult = new JsonResult();
        SysUser sysUser = new SysUser();
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        sysUser.setId(uuid);
        sysUser.setName("111111111");
        sysUser.setEnabled(true);
        sysUser.setCreatedDate(new Date());
        sysUserService.insertSysUser(sysUser);
        jsonResult.setData(sysUser);
        return jsonResult;
    }
    @RequestMapping("/del")
    public JsonResult del() {
        JsonResult jsonResult = new JsonResult();
        oauthAccessTokenService.deleteAll();
        //jsonResult.setData(oauthAccessToken);
        return jsonResult;
    }
}
